//----------------------------------------------------轮播图
let left = document.querySelector(".button-left")
let right = document.querySelector(".button-right")
let m = document.querySelectorAll(".m")
let images = document.querySelector(".images")
let index = 0
let time

function position(){
    images.style.left = (index * -100) + "%"
}
function add(){
    if(index >= m.length -1){
        index = 0
    }else{
        index++
    }
}
function desc(){
    if(index < 1){
        index = m.length -1
    }else{
        index--
    }
}
function timer(){
    time = setInterval(()=>{
        index++
        desc()
        add()
        position()
    },3000) 
}

left.addEventListener("click",()=>{
    desc()
    position()
    clearInterval(time)
    timer()
})
right.addEventListener("click",()=>{
    desc()
    position()
    clearInterval(time)
    timer()
})
for(let i = 0;i<m.length;i++){
    m[i].addEventListener("click",()=>{
        index = i
        index = position();
        clearInterval(time)
        timer()
    })
}



timer()
//----------------------------------轮播结束

// -----------------------------------按钮
let btn = document.querySelectorAll('button')
for (var i = 0; i < btn.length;i++){
    btn[i].onclick = function(){
        for(var j = 0; j < btn.length; j++){
            btn[j].style.color = "rgb(58,133,255";
            btn[j].style.backgroundColor = "#fff";
            this.style.backgroundColor = 'rgb(58,133,255)';
            this.style.color = '#fff'
            console.log(this.style.color);
        }
       
    }
   
}

//-----------------------------------按钮结束